<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>getJasonData</title>

		<script src="./js/jquery-1.4.2.min.js" type="text/javascript">
</script>

		<script src="./js/jquery.ui.core.min.js" type="text/javascript">
</script>
		<script src="./js/jquery.ui.widget.min.js" type="text/javascript">
</script>
		<script src="./js/jquery.easyui.min.js" type="text/javascript">
</script>
		<link rel="stylesheet" type="text/css"
			href="./styles/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="./styles/icon.css">

		<script>
$(function() {
	$('#dd')
			.dialog(
					{
						toolbar : [
								{
									text : 'Add',
									iconCls : 'icon-add',
									handler : function() {
										//alert('add')
									$("#test").empty();
								}
								},
								'-',
								{
									text : 'Save',
									iconCls : 'icon-save',
									handler : function() {
										//alert($("#test").text());
									var shortUrl = $("#test").text();
									var longUrl = $("#text1").val();
									var url = "http://localhost:8080/spring3upload_jquery/geturl/add?shortUrl="
											+ shortUrl + "&longUrl=" + longUrl;
									//$.post("http://localhost:8080/spring3upload_jquery/geturl/add?shortUrl="+shortUrl+"&longUrl="+longUrl);
									$.ajax( {
										type : 'POST',
										url : url,
										//data: data,
										dataType : 'text',
										success : function() {
											alert('ok');
										}
									});

								}
								} ],
						buttons : [ {
							text : 'Ok',
							iconCls : 'icon-ok',
							handler : function() {
								alert('ok');
							}
						}, {
							text : 'Cancel',
							handler : function() {
								$('#dd').dialog('close');
							}
						} ]
					});
});

function open1() {
	$('#dd').dialog('open');
}
function close1() {
	$('#dd').dialog('close');
}
</script>

	</head>

	<body>

		<script type="text/javascript">
$(document)
		.ready(
				function() {

					$("button")
							.click(
									function() {
										$('#dd').dialog('open');
										$("#test").empty();
										var longUrl = $("#text1").val();
										var url = "http://localhost:8080/spring3upload_jquery/geturl/getshorturl/?longUrl=";
										var fullRequest = url + longUrl;
										$.getJSON(fullRequest, function(field) {
											//$.each(data,function(i,field){
												//$("#test").append(field+"");
												//});

												eval("var p=" + field + ";");
												//alert(p.data.url);
												$("#test").append(p.data.url);

											});

									});
				});
</script>





		<button>
			A button element
		</button>




		<input name="text1" type="text" id="text1" />









		<div id="dd" icon="icon-save"
			style="padding: 5px; width: 400px; height: 200px;">
			<div id="test"></div>
		</div>




	</body>
</html>
